﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KTXD.Data;
using KTXD.Entities;
using System.Data;

namespace UserKTXD.Controls
{
    public partial class ControlThuVienAnh : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Pager1.CurrentIndex = 1;
                Bind_Data(Pager1.CurrentIndex);
            }
        }


        protected void Bind_Data(int PageNo)
        {
                int TotalRows = 0;
                string WhereClause = "1=1 and TrangThai=1";
                TList<BoSuuTap> TList_Menu = DataRepository.BoSuuTapProvider.GetPaged(WhereClause, "Id DESC", PageNo - 1, Pager1.PageSize, out TotalRows);
                drpThuVienAnh.DataSource = TList_Menu;
                drpThuVienAnh.DataBind();
                Pager1.ItemCount = TotalRows;
                H_PageCount.Value = Pager1.PageCount.ToString();
        }

        protected void Pager1_Command(object sender, CommandEventArgs e)
        {
            int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
            Pager1.CurrentIndex = currnetPageIndex;
            Bind_Data(currnetPageIndex);
        }

        protected void cmdNext_Click(object sender, EventArgs e)
        {
            if (Pager1.CurrentIndex < Convert.ToInt32(H_PageCount.Value))
            {
                //Thread.Sleep(2000);
                Pager1.CurrentIndex = Pager1.CurrentIndex + 1;
                Bind_Data(Pager1.CurrentIndex);
            }
        }

        protected void cmdPrevious_Click(object sender, EventArgs e)
        {
            if (Pager1.CurrentIndex > 1)
            {
                //Thread.Sleep(2000);
                Pager1.CurrentIndex = Pager1.CurrentIndex - 1;
                Bind_Data(Pager1.CurrentIndex);
            }
        }

        public string GetDienGiai(object Char)
        {
            int i = Convert.ToInt32(Char.ToString());
            TList<HinhAnh> TList_HinhAnh = DataRepository.HinhAnhProvider.GetByIdBoSuuTap(i);
            if (TList_HinhAnh.Count > 0)
                return TList_HinhAnh[0].Ten;
            else return "";
        }

        public string GetTieuDe(object Char)
        {
            string s = Char.ToString();
            return Common.ConvertToUnSign(s);
        }




    }
}